package org.example.cet.demos.controller;


import jakarta.validation.Valid;
import org.example.cet.demos.converter.converter;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.Result;
import org.example.cet.demos.domain.form.HwManageForm;
import org.example.cet.demos.domain.po.HwManage;
import org.example.cet.demos.domain.query.HwManageQuery;
import org.example.cet.demos.service.impl.HwManageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/hw-manage")
public class HwManageController {
    @Autowired
    private HwManageServiceImpl hwManageService;
    @Autowired
    private converter converter;

    @PostMapping("/add")
    public Result add(@Valid @RequestBody HwManageForm hwManageForm) {
        HwManage hwManage=converter.ToHwManage(hwManageForm);
        hwManageService.save(hwManage);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        hwManageService.removeById(id);
        return Result.success();
    }

    @PutMapping("/update/{id}")
    public Result update(@PathVariable Integer id,@Valid @RequestBody HwManageForm hwManageForm) {
        HwManage hwManage=converter.ToHwManage(hwManageForm);
        hwManage.setId(id);
        hwManageService.updateById(hwManage);
        return Result.success();
    }

    @GetMapping("/getPage")
    public Result getPage(HwManageQuery hwManageQuery) {
        PageBean pb=hwManageService.getPage(hwManageQuery);
        return Result.success(pb);
    }

}
